package j2024.j202407;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class j0726 {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long m = in.nextLong();
        long a = in.nextLong();
        long b = in.nextLong();
        long count = 0;
        if(n<2 && m<2){
            System.out.println(0);
        }else {
            long max = Math.min(n/2,m);
            //枚举a礼包
            for (long i = 0; i <= max; i++) {
                long c1 = a * i;
                long c2 = b * Math.min((n/2)-i,(m-i)/2);
                count = Math.max(count,(c1+c2));
            }
            System.out.println(count);
        }
    }


    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] price = new int[n];
        for (int i = 0; i < n; i++) {
            price[i] = in.nextInt();
        }
        int count = 0;
        for(int i = 1;i < n;i++){
            if(price[i]>price[i-1]){
                count+=(price[i]-price[i-1]);
            }
        }
        System.out.println(count);
    }


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String[] ret = str.split(" ");
        for (int i = ret.length-1; i >= 0; i--) {
            System.out.print(ret[i]+" ");
        }
    }

    /**
     * 814. 二叉树剪枝
     * @param root
     * @return
     */
    public TreeNode pruneTree(TreeNode root) {
        if(root==null){
            return null;
        }
        root.left = pruneTree(root.left);
        root.right = pruneTree(root.right);
        if(root.left==null && root.right==null && root.val==0){
            return null;
        }
        return  root;
    }

    /**
     * 98. 验证二叉搜索树
     */
    public long prev = Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        if(root==null){
            return true;
        }
        boolean left = isValidBST(root.left);
        if(left==false){
            return false;
        }
        boolean cur = false;
        if(prev<root.val){
            cur = true;
        }
        if(cur==false){
            return false;
        }
        prev = root.val;
        boolean right = isValidBST(root.right);
        return left && cur && right;
    }

    /**
     * 230. 二叉搜索树中第K小的元素
     */
    int cur = 0;
    int count = 0;
    public int kthSmallest(TreeNode root, int k) {
        count = k;
        smllset(root);
        return cur;
    }
    public void smllset(TreeNode root){
        if(root==null|| count==0){
            return;
        }
        smllset(root.left);
        if(count==0){
            return;
        }
        cur = root.val;
        count--;
        if(count==0){
            return;
        }
        smllset(root.right);
    }


    /**
     * 257. 二叉树的所有路径
     */
    List<String> ret;
    public List<String> binaryTreePaths(TreeNode root) {
        ret = new ArrayList<>();
        StringBuilder path = new StringBuilder();
        dfs(root,path);
        return ret;
    }
    public void dfs(TreeNode root,StringBuilder _path){
        StringBuilder path = new StringBuilder(_path);
        if(root.left==null && root.right==null){
            path.append(root.val);
            ret.add(path.toString());
            return;
        }else {
            path.append(root.val);
            path.append("-");
            path.append(">");
        }
        if(root.left!=null){
            dfs(root.left,path);
        }
        if(root.right!=null){
            dfs(root.right,path);
        }
    }
}
